var prodList =[];
var schooseId=0;
var searchNo="";
var isbuyNum ;
var total  ; 
/* ---- 表单验证  -----*/   
function submitForm() {
	if($("#showProductId").val() == "") {
		layer.alert("请选择商品编号！");
		return;
	}
	if($("#exchangeType").val() == "0") {
		layer.alert("请选择退换货类型！");
		return;
	}
	if($("#reson").val() == "") {
		layer.alert("请选择请选择退货原因！");
		return;
	}
	if(	schooseId==0){
		layer.msg('请选择商品id在进行操作!',{icon:1,time:1000},function(){
		});
		return;
	}
	var prov_v= $('#provId option:selected').text();
	var city_v= $('#cityId option:selected').text();
	var area_v= $('#areaId option:selected').text();
	
	var provid_ = $("#provId").val();
	var cityid_ = $("#cityId").val();
	var areaid_ = $("#areaId").val();
	if(provid_ ==0 || provid_ ==""){ 
		layer.msg('请选择省份在进行操作!',{icon:1,time:1000},function(){
		return;
		});
	}
	if(cityid_ ==0 || cityid_ ==""){ 
		layer.msg('请选择市在进行操作!',{icon:1,time:1000},function(){
		return;
		}); }
	if(areaid_ ==0 || areaid_ ==""){ 
		layer.msg('请选择区在进行操作!',{icon:1,time:1000},function(){
		return;
	});}
	 
	$("#provCityArea").val(prov_v+city_v+area_v);
	var exchangeType=$("#exchangeType").val();
	var reson=$("#reson").val();
	if(exchangeType ==0 || exchangeType ==""){ 
		layer.msg('请选择退换货类型在进行操作!',{icon:1,time:1000},function(){
		return;
		});
	}
	if(reson ==0 || reson ==""){ 
		layer.msg('请选择退换货原因在进行操作!',{icon:1,time:1000},function(){
		return;
		});
	}
	$("#query_form").submit();
	/*submitFormDate();*/
}

/* ---------商品数据封装请求------------*/
function searchAjaxJson(path) {
	
	var orderNo = $("#orderNo").val();
	if(orderNo == "") {
		layer.alert('请输入订单编号！');
		return;
	}
	$.ajax({
 		url:path+"/exchange/exchange_refund_apply",
 		data:{"orderNo":orderNo,"mathid":Math.random()}, 
 		type:"post",
 		dataType:"text",
 		success:function(json){
 			
 			schooseId=0;
 			span_empty();
 		    $('input[id!="orderNo"][id!="sunmitForm"]').val("");//[id!="provId"][id!="cityId"][id!="areaId"][id!="exchanger"][id!="tel"][id!="phone"][id!="recpostNo"]
 			if(json!="false")
 			{
 	 			var jsonobj = JSON.parse(json); 
 	 			var productList = jsonobj['productList'];
 	 			if(null != productList)
 	 			{
 	 				prodList =productList;
 	 			}
 	 			searchNo = jsonobj['orderNo'];
 	 			
 	 			
 	 			var htext = "<option value=''>请选择商品编号</option>";
 	 			for (var i = 0; i < productList.length; i++) 
 	 			{
 	 				/*htext+='<button type="button" class="btn btn-primary radius" onclick="chooseId('+productList[i]['pid']+')" id="" name="">'+productList[i]['pid']+'</button>';
 	 				htext+="&nbsp;&nbsp;"*/
 	 				htext += "<option value='" + productList[i]['pid'] + "'>" + productList[i]['pid'] + "</option>"
 	 			}
 	 			$("#showProductId").html(htext);
 	 			
 	 			$("#exchanger").val(jsonobj['recName'] );
 	 			$("#tel").val(jsonobj['recPhone'] );
 	 			$("#phone").val(jsonobj['mobil'] );
 	 			$("#recpostNo").val(jsonobj['recPostno'] );
 	 			$("#address").val(jsonobj['recAddress'] );
 	 	 		
 	 		/*	$("#tel").val(jsonobj['recPhone'] );
 	 			$("#phone").val(jsonobj['mobil'] );
 	 			$("#recpostNo").val(jsonobj['recPostno'] );*/
 	 			 
 	 			changeProvCityArea(1,jsonobj['recProv']);
 	 			changeProvCityArea(2,jsonobj['recCity']);
 	 			//changeProvCityArea(3,jsonobj['recArea']);
 	 			$("#provId option[value='"+jsonobj['recProv']+"']").attr("selected", true);
 	 			$("#cityId option[value='"+jsonobj['recCity']+"']").attr("selected", true);
 	 			$("#areaId option[value='"+jsonobj['recArea']+"']").attr("selected", true);
 	 		 
 	 			//$("#provId").find("option:contains('"+jsonobj['recProv']+"')").attr("selected",true);
 	 			//$("#cityId").find("option:contains('"+jsonobj['recCity']+"')").attr("selected",true);
 	 			//$("#areaId").find("option:contains('"+jsonobj['recArea']+"')").attr("selected",true);
 	 			
 			}else{
 				$("#showProductId").html("<option value=''>请选择商品编号</option>");
 				layer.msg('查询结果不符合,请输入完整的订单号!',{icon:1,time:1000},function(){});
 			}
 			
 		},
 		error:function(){
 				$("#showProductId").html("<option value=''>请选择商品编号</option>");
 				layer.msg('查询结果不符合,请输入完整的订单号!',{icon:1,time:1000},function(){});
 		}
 	});	
 

}

/*----- ****** ----- */
function toEmpty() {
	 
	$("#orderNo").val(""); 
	$("#prodName").val(""); 
	$("#exchanger").val(""); 
	$("#exchangeType").val(""); 
	$("#exchangeStatus").val(""); 
	$("#startDate").val(""); 
	$("#endDate").val(""); 
}
/* ---- 记录选择id 迭代 商品项 -----*/   
function chooseId(id){
	if(id == "") {
		$("#v_orderNo").html("") ;
		$("#orderNo_s").val("") ;
		
		$("#v_prodName").html("") ;
		$("#prodName").val("") ;
		
		$("#v_prodNo").html("") ;
		$("#prodNo").val("") ;
		
		$("#v_prodMileage").html("") ;
		$("#prodMileage").val("");   
		
		$("#v_buyNum").html("") ;
		$("#buyNum").val("");   
		
		$("#v_total").html("") ;
		$("#backMileage").val("");
		return;
	}
	for (var int = 0; int < prodList.length; int++) {
		schooseId=id;
		$("#prodId").val(id);
		if(prodList[int]['pid'] == id){
	 
			$("#v_orderNo").html(searchNo) ;
			$("#orderNo_s").val(searchNo) ;
			
			$("#v_prodName").html(prodList[int]['prodName']) ;
			$("#prodName").val(prodList[int]['prodName']) ;
			
			
			$("#v_prodNo").html(prodList[int]['prodNo']) ;
			$("#prodNo").val(id) ;
			
			$("#v_prodMileage").html(prodList[int]['prodMileage']) ;
			$("#prodMileage").val(prodList[int]['prodMileage']);   
			
			$("#v_buyNum").html(prodList[int]['buyNum']) ;
			$("#buyNum").val(prodList[int]['buyNum']);   
			
			total =  prodList[int]['prodMileage']*prodList[int]['buyNum'] ;
			$("#v_total").html(total) ;
			$("#backMileage").val( total );    
		}
	}
	
}
/* ---- 清空span -----*/     
function span_empty(){
	$("#showProductId").html("<option value=''>请选择商品编号</option>");
	$("#prodId").val("");
	$("#v_orderNo").empty(); 
	$("#v_prodName").empty(); 
	$("#v_prodNo").empty(); 
	$("#v_prodMileage").empty(); 
	$("#v_buyNum").empty(); 
	$("#v_total").empty(); 
} 
 
/*-----提交标单 ----- */
function  submitFormDate(){
	$("#query_form").ajaxSubmit({
		dataType : 'html',
        success: function(message){
        		if(message == "true"){
                    layer.msg('操作成功!',{icon:1,time:1000},function(){
                    	parent.window.location.href = parent.window.location.href;
                    });
 				}else if(message == "500"){
 					layer.alert("系统繁忙！");
 				}else{
 					layer.alert(message);
 				}
        },
        error: function(){
            layer.msg('操作失败!',{icon:5,time:1000});
        }
    });
}
 